﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.Data;
namespace HA.ModFlow.Controls.Windows.Scatter
{
    /// <summary>
    /// winScatter2DPoints.xaml 的交互逻辑
    /// </summary>
    public partial class winScatter2DPoints : Window
    {
        public winScatter2DPoints( List <ScatterPoint> scatter,string str)
        {
            InitializeComponent();
            this._scatterPoints = scatter;
            this.labDataset.Text = "数据名称: "+str ;

            MenuItem itemCopy = new MenuItem();
            itemCopy.Header = "复制";
            itemCopy.Command = ApplicationCommands.Copy;

            //MenuItem itemPaste2 = new MenuItem();
            //itemPaste2.Header = "粘贴";
            //itemPaste2.InputGestureText = "Ctrl+V";
            //itemPaste2.Click += new RoutedEventHandler(itemPaste2_Click);

            ContextMenu cm = new ContextMenu();
            cm.Items.Add(itemCopy);
            //cm.Items.Add(itemPaste2);          
            this.dtGrid.ContextMenu = cm;
            
        }
        private List<ScatterPoint> _scatterPoints = new List<ScatterPoint>();

        public List<ScatterPoint> ScatterPoints
        {
            get { return _scatterPoints; }
            set { _scatterPoints = value; }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.dtGrid.AutoGenerateColumns = false;
            this.dtGrid.CanUserAddRows = false;
            this.dtGrid.CanUserSortColumns = false;
            DataGridTextColumn txt = new DataGridTextColumn();
            txt.Header = "编号";
            Binding bin = new Binding("Id");
            txt.Binding = bin;
            txt.IsReadOnly = true;
            this.dtGrid.Columns.Add(txt);

            txt = new DataGridTextColumn();
            txt.Header = "X";
            bin = new Binding("X");
            bin.StringFormat = "#.##";
            txt.Binding = bin;
            this.dtGrid.Columns.Add(txt);

            txt = new DataGridTextColumn();
            txt.Header = "Y";
            bin = new Binding("Y");
            bin.StringFormat = "#.##";
            txt.Binding = bin;
            this.dtGrid.Columns.Add(txt);

            if (this.ScatterPoints.Count > 0)
            {
                int count = this.ScatterPoints[0].Values.Count;
                for (int i = 0; i < count; i++)
                {
                    txt = new DataGridTextColumn();
                    txt.Header ="值_"+ (i + 1).ToString();
                    string str = "Values[" + i + "]";
                    bin = new Binding(str );
                    bin.StringFormat = "#.##";
                    txt.Binding = bin;
                    this.dtGrid.Columns.Add(txt);
                }
            }

            this.dtGrid.ItemsSource = ScatterPoints;

        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
           
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void dtGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = (e.Row.GetIndex() + 1).ToString();
        }
    }
}
